/**
 * Name: Process.java
 * @author William Holland
 */
public class Process {
	protected int number, length, priority, inputSize, outputSize, tempSize, diskBaseAddress, size; 
	protected int programCounter, ramBaseLocation, numIO;
	protected long startWaitTime, endWaitTime, waitTime, startExecTime, endExecTime, execTime;
	public static enum State{ NEW, RUNNING, WAITING, READY, TERMINATED;}	
	protected boolean inRam = false;
	protected long[] registers = new long[16];
	protected Page[] pageTable;
	protected State state = State.NEW;
	
	public Process(	int jobNumber, int jobLength, int jobPriority, int inputBufferSize,
					int outputBufferSize, int tempBufferSize, int locationOnDisk, int sizeOnDisk){
		number = jobNumber;
		length = jobLength;
		priority = jobPriority;
		inputSize = inputBufferSize;
		outputSize = outputBufferSize;
		tempSize = tempBufferSize;
		diskBaseAddress = locationOnDisk;
		size = sizeOnDisk;		
		int numberOfPages = (size / 4);
		if(size%4 > 0)
			numberOfPages++;
		pageTable = new Page[numberOfPages];
		for(int i = 0; i < numberOfPages; i++){
			pageTable[i] = new Page();
			pageTable[i].number = i;
		}
			
	}
	/**
	 * Method used to set current time for process waiting
	 * and execution times.  
	 * @param waitTime True for setting a wait time. False for setting ExecTime
	 * @param startTime True for setting a startTime. False for setting EndTime
	 */
	protected void setTime(boolean waitTime, boolean startTime){
		long cTime = System.currentTimeMillis(); 
		if(waitTime){
			if(startTime){
				startWaitTime = cTime;
			}
			else{
				endWaitTime = cTime;
			}
		}
		else{
			if(startTime){
				startExecTime = cTime;
			}
			else{
				endExecTime = cTime;
			}	
		}
	}
	
	/**
	 * Method returns the total time (in milliseconds) spent
	 * either waiting for the CPU or time spent executing on 
	 * the CPU.
	 * @param waitTime True for time spent waiting. False for time spent Executing.
	 * @return
	 */
	protected long getTime(boolean waitTime){
		if(waitTime){
			this.waitTime = endWaitTime - startWaitTime;
			return this.waitTime;
		}
		else{
			execTime = endExecTime - startExecTime;
			return this.execTime;
		}
	}
}
